package moriarty.gwt.shared;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.RootPanel;


public class Utils {

	/**
	 * Escape an html string. Escaping data received from the client helps to
	 * prevent cross-site script vulnerabilities.
	 * 
	 * @param html the html string to escape
	 * @return the escaped string
	 */
	public static final String escapeHtml(String html) {
		if (html == null) {
			return null;
		}
		return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
				.replaceAll(">", "&gt;").replaceAll("\"", "\\\"");
	}
	
    /**
     * The email addresses were taking 1-2 seconds to pop up on screen, so I added a loading gif
     * in the html that must be hidden once the RPC call to retrieve the stored names is done. 
     */
	public static final void hideLoadingScreen(){
		 DOM.removeChild(RootPanel.getBodyElement(), DOM.getElementById("loading"));
	}
	

}
